<template>
    <div style="width: 100%">
        <table class="layui-hide" id="twoagent_list" lay-filter="twoagent_list"></table>
        <script type="text/html" id="twoagentsBar">
            <a class="layui-btn layui-btn-xs" lay-event="detils">详情</a>
        </script>
    </div>
</template>

<script>
	import fenxiaoapi from '../../common/fenxiaoserver.js';
		import bus from '../../common/bus';
export default {
    name: 'twoagent',
    data() {
        return {
            twoagent_list : [],
			table: false
        };
    },
	created(){
		
	},
    components: {
      
    },
    computed: {
        
    },
	mounted() {
	    this.getlist();
	},
	activated() {
	    if (!this.table) return;
	    this.table.resize('twoagent_list');
	},
    methods: {
		getlist(){
			var _this = this;
			layui.use('table', function () {
			    _this.table = layui.table;
			    _this.table.render({
			        elem: '#twoagent_list',
			        url: _this.url + '/twoagent_list',
			        where: { token: _this.vuex_user.token },
			        cellMinWidth: 80,
			        cols: [
			            [
			                { field: 'id',width: 80,title: 'ID', sort: true },
			                { field: 'fnickname',width: 160, title: '代理名称' },
			                { field: 'iscompany',width: 160, title: '是否机构', sort: true },
			                { field: 'fphone',  title: '联系方式', sort: true },
							{ field: 'fstate',width: 100,  title: '状态', sort: true },
							{ field: 'faddtime', title: '时间', sort: true },
							{ fixed: 'right', title: '操作', toolbar: '#twoagentsBar' }
			            ]
			        ],
			        height: $('.content').height() - 20,
			        page: true,
			        limit: 10,
			        toolbar: true,
			        parseData: function (res) {
						console.log(res)
						res.data.list.forEach((item,index,array)=>{
						    //执行代码
							item.faddtime = item.faddtime.replace('T',' ')
							if(item.fstate == 'normal'){
								item.fstate = '<span style="color:blue;">正常</span>';
							}else if(item.fstate == 'islock'){
								item.fstate = '锁定';
							}else{
								item.fstate = '<span style="color:red;">删除</span>';
							}
							
							item.iscompany = '<span style="color:red;">否</span>';
							if(item.fcompany != null && item.fcompany.length > 0){
								item.iscompany = item.fcompany;
							}
						})
			            return {
			                code: 0, //解析接口状态
			                msg: res.msgs, //解析提示文本
			                count: res.data.nums.nums, //解析数据长度
			                data: res.data.list //解析数据列表
			            };
			        }
			    });
				bus.$on('collapse-content', (msg) => {
				    setTimeout(function () {
				        _this.table.resize('twoagent_list');
				    }, 300);
				});
			    _this.table.on('tool(twoagent_list)', function (obj) {
			        var data = obj.data;
			        if (obj.event === 'del') {//删除点击
			            layer.confirm('真的删除行么', function (index) {
			                obj.del();
			                layer.close(index);
			                _this.del(data);
			            });
			        }
			        else if (obj.event === 'detils') {//详情点击
			            _this.detils(data);
			        } else if (obj.event === 'edit') {//编辑点击
			            _this.edit(data);
			        }
			    });
			});
		}
    }
};
</script>


<style scoped>

</style>
